package com.tong.embeddedvr.controller;

import com.tong.embeddedvr.dto.HostAccountDTO;
import com.tong.embeddedvr.service.impl.HostAccountServiceImpl;
import com.tong.embeddedvr.utils.CommonUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.HashMap;

@CrossOrigin
@RestController
@RequestMapping("/hostaccount")
public class HostAccountController {
    @Autowired
    private HostAccountServiceImpl hostAccountServiceImpl;

    private static final Logger logger = LoggerFactory.getLogger(HostAccountController.class);

    @RequestMapping("/getall")
    public String getAll(HttpSession session){
        return hostAccountServiceImpl.getAllHostAccount();
    }

    @RequestMapping("/updateinformation")
    public String updateInformation(HttpSession session,HostAccountDTO hostAccountDTO){
        return hostAccountServiceImpl.updateInformation(hostAccountDTO);
    }

    @RequestMapping("/delete")
    public String delete(HttpSession session,HostAccountDTO hostAccountDTO){
        hostAccountDTO.setHostAccountIsDelete(1);
        return hostAccountServiceImpl.updateInformation(hostAccountDTO);
    }

    @RequestMapping("/gethostaccount")
    public String gethostaccount(HttpSession session){
        String res = null;
        try {
            res = hostAccountServiceImpl.allocateHostAccount(session);
        } catch (Exception e) {
            res = CommonUtil.ajaxReturn(400,"账号分配失败");
            logger.error("账号分配失败");
            logger.error("错误信息:[{}]",e.getMessage());
            e.printStackTrace();
        }
        return res;
    }

    @RequestMapping("/test")
    public String test(){
        return CommonUtil.ajaxReturn("test成功");
    }
}